import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/connection',
  detail = '/connection/subscribe',
  close = '/connection/close',
}

/**
 * 列表接口
 * @param params
 */
export const list = (params) => {
  return defHttp.post({ url: Api.list, params });
};

/**
 * 详情
 * @param params
 */
export const detailOrUpdate = (params) => {
  return defHttp.post({ url: Api.detail, params }, { isTransformResponse: false });
};
/**
 * 下线
 */
export const closeRequest = (params, handleSuccess) => {
  return defHttp.post({ url: Api.close, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 */
export const batchCloseRequest = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认下线',
    content: '是否确认下线选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.close, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
